package com.yan.kfgl.service.dao.spring;

import java.util.Date;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.yan.kfgl.model.MNUser;
import com.yan.kfgl.service.dao.facade.UserDaoService;

public class UserDaoServiceSpringImpl extends HibernateDaoSupport implements UserDaoService{

	@Override
	public MNUser findUserByNameAndPassword(MNUser user) {
		MNUser tmp = null;
		String hql = "from MNUser where name=? and password=?";
		if(user!=null&&user.getName()!=null&&user.getPassword()!=null){
			List users = super.getHibernateTemplate().find(hql, new Object[]{ user.getName() , user.getPassword()});
			if(users!=null && users.size()>0){
				tmp =  (MNUser) users.get(0);
			}
		}
		return tmp;
	}

	@Override
	public void saveOrUpdate(MNUser user) {
		if(user != null){
			super.getHibernateTemplate().saveOrUpdate(user);
		}
	}

	@Override
	public MNUser findUserByName(MNUser user) {
		user = (MNUser)super.getHibernateTemplate().get(MNUser.class, user.getName());
		return user;
	}

}
